import { getCategory1ListApi,getCategory2ListApi,getCategory3ListApi } from '@/api/product/category';
import { defineStore } from 'pinia';
import type {Category} from './interface'

export const useCategoryStore = defineStore('Category',{
    state:():Category=>{
        return {
            category1Id: undefined,
            category2Id: undefined,
            category3Id: undefined,
            category1List: [],
            category2List: [],
            category3List: [],
        }
    },
    getters:{},
    actions:{
        // 获取一级
        async getCategory1List(){
            this.category1List = await getCategory1ListApi()
            // console.log(this.category1List);
            
        },
        // 获取二级
        async getCategory2List(category1Id:number){
            this.category2List = await getCategory2ListApi(category1Id)
            this.category1Id = category1Id
            // 让二三级分类不选中
            this.category2Id = undefined;
            this.category3Id = undefined;
            // 清空三级分类列表
            this.category3List = [];
        },
        // 获取三级
        async getCategory3List(category2Id:number){
            this.category3List = await getCategory3ListApi(category2Id)
            this.category2Id= category2Id
            // 第三级不选中
            this.category3Id = undefined;
        },
    }
})
    
    
    
